﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CheckInternet
{
    public enum InternetConnectionState
    {
        INTERNET_CONNECTION_MODEM = 0x01,
        INTERNET_CONNECTION_LAN = 0x02,
        INTERNET_CONNECTION_PROXY = 0x04,
        INTERNET_CONNECTION_OFFLINE = 0x20,
        INTERNET_CONNECTION_CONFIGURED = 0x40
    }

    class Program
    {
        private static InternetConnectionState dwFlag = InternetConnectionState.INTERNET_CONNECTION_CONFIGURED;

        [DllImport("winInet.dll")]
        private static extern bool InternetGetConnectedState(
            ref   InternetConnectionState dwFlag,
            int dwReserved
            );

        public static bool IsInternetActive()
        {
            return InternetGetConnectedState(ref dwFlag, 0);
        }

        static void Main(string[] args)
        {
            if (IsInternetActive())
            {
                Console.WriteLine("InternetActive");
            } 
            else
            {
                Console.WriteLine("Internet NOT Active");
            }
            Console.ReadLine();
        }
    }
}
